// src/stores/websiteStore.ts
import { defineStore } from 'pinia'
import { fetchLinkCategory } from '@/services/apis/tools/website'

interface WebsiteState {
  categoryList: Array<{
    id: number
    name: string
    order: number
  }>
}

export const useWebsiteStore = defineStore('website', {
  state: (): WebsiteState => ({
    categoryList: []
  }),
  actions: {
    async fetchCategories() {
      try {
        const res = await fetchLinkCategory()
        this.categoryList = res.list
        return Promise.resolve(res.list)
      } catch (error) {
        console.error('获取分类失败:', error)
        return Promise.reject(error)
      }
    },
  },
  persist: true // 启用持久化插件
})
